<?php 
	$theme_color = ($the_directory->getThemeColor() != null && $the_directory->getThemeColor() != '') ? $the_directory->getThemeColor() : '#90cd67';
?>
<!-- 
<link href="../js/styleChanger/changer.css" media="screen" type="text/css" rel="stylesheet">

<link href="../js/styleChanger/colorpicker/colorpicker.css" type="text/css" rel="stylesheet">
 -->

		<style type="text/css" id="cFontStyleWColor1">
			a, .color_3, q:before, blockquote:before, .blog .post h2.entry-title a:hover, .portfolio_container .portfolio .entry-title a:hover, ul.p_filter li.current a, ul.p_filter li a:hover, .blog.short .post .entry-title a:hover, .widgetinfo, h5 { color:<?php echo $theme_color ?>; }
		</style>
		
		<style type="text/css" id="cFontStyleWColor2">
			code:before, span.dropcap2, .table thead th, .colored_block, #navigation li.current_page_item > a, #navigation li:hover > a:hover, #navigation ul li:hover > a, .post .published, .shortcode_slideshow ul.shortcode_slideshow_pager li.current a, .shortcode_slideshow ul.shortcode_slideshow_pager li a:hover, .wp-pagenavi a, .cmsmsLike:hover, .cmsmsLike.active, .button, .button_medium, .button_large, .cmsms_slider_parent a.cmsms_prev_slide:hover span, .cmsms_slider_parent a.cmsms_next_slide:hover span, .cmsms_slider_parent a.cmsms_close_video:hover, .cmsms_slider_parent ul.cmsms_slides_nav li.active a, .cmsms_slider_parent ul.cmsms_slides_nav li:hover a, .cmsms_content_slider_parent ul.cmsms_slides_nav li.active a, .cmsms_content_slider_parent ul.cmsms_slides_nav li:hover a, .logo img {background-color:<?php echo $theme_color ?>;}
		</style>
		
		<style type="text/css" id="cFontStyleWColor3">
			#bottom .cmsms-form-builder input[type="text"]:focus, #bottom .cmsms-form-builder textarea:focus, input[type="text"]:focus, textarea:focus, .cmsmsLike:hover, select.resp_navigation:focus {border-color:<?php echo $theme_color ?>;}
		</style>
		
		<style type="text/css" id="cFontStyleWColor4">
			#header, #navigation > li > ul > li:first-child > a {border-top-color:<?php echo $theme_color ?>;}
		</style>
		
		<style type="text/css" id="cFontStyleWColor5">
			#navigation ul li.current_page_item:first-child > a:before, #navigation ul li:first-child > a:hover:before, #navigation ul li.current_page_item:first-child:hover > a:hover:before, #navigation ul li:first-child > a:before {border-bottom-color:<?php echo $theme_color ?>;}
		</style>								
<!--
<script src="../js/styleChanger/colorpicker/colorpicker.js" type="text/javascript"></script>

<script src="../js/styleChanger/changer.js" type="text/javascript"></script>

 

	<div id="stlChanger" style="position: absolute;">
			<div class="blockChanger bgChanger" style="left: 0px;">
				<a class="chBut" href="#">&nbsp;</a>
				<div class="chBody" style="display: block;">
					<div class="stBlock">
						<span>pick color</span>
						<div class="stColorParent">
							<a class="stColor2" href="#"><span style="background-color: rgb(245, 0, 0);" title="90cd67" id="cFontWColor1">&nbsp;</span></a>
						</div>
					</div>
					<div class="stBlock">
						<span>use preset</span>
						<div class="hdrStBgs">
							<div class="hdrCols">
								<span title="90cd67" style="background-color:#90cd67;" class="current">&nbsp;</span>
								<span title="9e86ae" style="background-color:#9e86ae;">&nbsp;</span>
								<span title="2fd2ea" style="background-color:#2fd2ea;">&nbsp;</span>
								<span title="ff6b39" style="background-color:#ff6b39;">&nbsp;</span>
								<span title="e1565c" style="background-color:#e1565c;">&nbsp;</span>
								<span title="ff3973" style="background-color:#ff3973;">&nbsp;</span>
								<div class="cl"></div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		
		<div class="colorpicker" id="collorpicker_861" style="left: 10px; top: 424px; display: block;"><div class="colorpicker_color" style="background-color: rgb(106, 255, 0);"><div><div style="left: 75px; top: 79px;"></div></div></div><div class="colorpicker_hue"><div style="top: 110px;"></div></div><div class="colorpicker_new_color" style="background-color: rgb(85, 120, 60);"></div><div class="colorpicker_current_color" style="background-color: rgb(144, 205, 103);"></div><div class="colorpicker_hex"><input type="text" size="6" maxlength="6"></div><div class="colorpicker_rgb_r colorpicker_field"><input type="text" size="3" maxlength="3"><span></span></div><div class="colorpicker_rgb_g colorpicker_field"><input type="text" size="3" maxlength="3"><span></span></div><div class="colorpicker_rgb_b colorpicker_field"><input type="text" size="3" maxlength="3"><span></span></div><div class="colorpicker_hsb_h colorpicker_field"><input type="text" size="3" maxlength="3"><span></span></div><div class="colorpicker_hsb_s colorpicker_field"><input type="text" size="3" maxlength="3"><span></span></div><div class="colorpicker_hsb_b colorpicker_field"><input type="text" size="3" maxlength="3"><span></span></div><div class="colorpicker_submit"></div></div>
		
	 -->
<?php 
	$template = Doctrine_Core::getTable ( 'Template' )->find($template_id);
	
?>
<?php slot('title') ?>
	<?php echo $title_content ?>
<?php end_slot() ?>


<?php slot('home') ?>
	<a href="http://<?php echo $the_directory->getDomain()?>"><?php echo $the_directory->getDomain()?></a>
<?php end_slot() ?>

<?php slot('rights') ?>
	<a style="color: #909090; font-size: 14px;text-decoration:none" href="http://<?php echo $the_directory->getDomain()?>"><?php echo $the_directory->getDomain()?></a>
<?php end_slot() ?>


<?php slot('meta_description') ?>

	<meta name="description" content="<?php echo $meta_description ?>" >

<?php end_slot() ?>

<?php slot('meta_keyword') ?>

	<meta  name="keywords" content="<?php echo $meta_kw ?>">

<?php end_slot() ?>




<?php //echo html_entity_decode($body_content) ?>

<?php 

$comment_tag = "##%%##comments##%%##";

$body_arr = explode($comment_tag, $body_content, 2);

?>
<div style="clear:both">
<?php echo html_entity_decode($body_arr[0]);?>
</div>

<?php 

if (count($body_arr) > 1){
	
	if ($template->getShowComments() == 1){
		?>
		<div style="clear:both">
			<?php 
			include_partial("comments/comments", array('comments' => $comments, 'comment_fields' => $comment_fields, 'template' => $template, 'category_content_ids' => $category_content_ids, 'show_rating' => $show_rating, 'directory' => $the_directory));
			?>
		</div>
	<?php }?>

		<div style="clear:both">
		<?php echo html_entity_decode(str_replace($comment_tag, "", $body_arr[1]));?>
		</div>
<?php }?>



<?php slot('footer') ?>
	<?php
	$i = 0;
	
	$uri = sfContext::getInstance()->getRequest()->getUri();
	$base_url = substr($uri, 0, strrpos($uri, '/') + 1);
	
	foreach ($footer_url as $url){
		$i++;
		echo '<div class="one_third" style="padding-bottom:8px;width:31%;"><a href="'. $base_url . DirectoryUtils::slugify($url) .'.html">'. str_replace('-', ' ', $url)  .' </div></a>';
		if ($i % 3 == 0){
			echo '<div style="clear:both"></div>';
		}
		
	}
	
	?>
<?php end_slot() ?>	


<?php slot('search') ?>
<div>
	<h3 style="color: orange; font-size: 18px; margin-bottom: 0;"><?php echo $the_directory->getSearchTitle()?></h3>
</div>
<div class="entry-meta post_img_bot">
	<form action="<?php echo url_for("template_generation/search") ?>" method="post" name="search_form" id="search_form">
		<?php 
		
		$max_inclusive_variables = 0;
		$inclusive_variables = 0;
		$i = 0;
		foreach ($searchComponents as $searchComponent) {
			$level = $searchComponent[0];
			$variables = $searchComponent[1];
			
			if(count($variables) == 1){
				// exclusive
				?>
				<div style="float: left;margin-left: 5px;" class="search_div">
					<span>
						<?php echo $level->getName().": ";?>
					</span>
					<?php 
					$the_table = Doctrine_Core::getTable ( 'Level' );
					$the_table->setTreePath();
					$the_table->findTreePath($level);
					$tree_path = $the_table->getTreePath();
					$category_content = Doctrine_Core::getTable('CategoryContent');
					$category_content->setContentArr();
					$contents = Doctrine_Core::getTable('CategoryContent')->getContentsByTreePath($tree_path, $level->getCategoryId());
					
					//usort($contents, array('CategoryContent', 'compareChildren'))
					
					?>
					<select id="<?php echo str_replace(" ", "_", $variables[0]);?>" name="<?php echo str_replace(" ", "_", $variables[0]);?>" class="search_select">
						<option value="">--<?php echo __("Select")?>--</option>
						<?php 
							foreach ($contents as $content) {
							?>
							<option value="<?php echo $content->getId();?>"><?php echo $content->getName();?></option>
							<?php 
							}
						?>
					</select>
				</div>
				<?php 
			}else{
			   // inclusive
			   ?>
			   
			   <div style="float: left;margin-left: 5px;">
						<div style="float:left"  class="search_div">
							<?php echo $level->getName().": ";?>
						</div>
						<?php 
						$the_table = Doctrine_Core::getTable ( 'Level' );
						$the_table->setTreePath();
						$the_table->findTreePath($level);
						$tree_path = $the_table->getTreePath();
						$category_content = Doctrine_Core::getTable('CategoryContent');
						$category_content->setContentArr();
						$contents = Doctrine_Core::getTable('CategoryContent')->getContentsByTreePath($tree_path, $level->getCategoryId());
						
						//$to_refresh = count($variables) > 2 ?  $variables[2] : ""; 
						$inclusive_variables ++;
						?>
						<div style="float:right"  class="search_div" >
						<select id="<?php echo str_replace(" ", "_", $variables[0]) ;?>" name="<?php echo str_replace(" ", "_", $variables[0]);?>" onchange="getChildrendata('<?php echo  str_replace(" ", "_", $variables[1])?>', $(this).attr('value'))" class="search_select">
						<option value="">--<?php echo __("Select")?>--</option>	
							<?php 
								foreach ($contents as $content) {
								?>
								<option value="<?php echo $content->getId();?>"><?php echo $content->getName();?></option>
								<?php 
								}
							?>
						</select>
						</div>
					
					
					
						<?php for ($i = 1; $i < count($variables); $i++) {
								$inclusive_variables++;
								//$onchange_param = $i + 2 < count($variables)-1 ?  $variables[$i+2] : "";
								$onchange_str = $i + 1 < count($variables)? "getChildrendata('". str_replace(" ", "_", $variables[$i+1]) ."', $(this).attr('value'))" : "";
								
							?>
							<div style="clear:both">
								<div style="float:left"  class="search_div">
									<?php 
									$pieces = explode('.', $variables[$i]);
									echo $pieces[count($pieces) - 1].": ";
									?>
								</div>
								<div style="float:right"  id="<?php echo $variables[$i]?>_div"  class="search_div">
									<select id="<?php echo str_replace(" ", "_", $variables[$i]);?>" name="<?php echo str_replace(" ", "_", $variables[$i]);?>" onchange="<?php echo $onchange_str?>" class="search_select">
											<option value="">--<?php echo __("Select")?>--</option>
									</select>
								</div>
							</div>
							
							<?php 
						}?>
					
				</div>
			   
			   <?php 
			}
			if($inclusive_variables > $max_inclusive_variables){
				$max_inclusive_variables = $inclusive_variables;
			}
			$inclusive_variables = 0;
		}
		
		$max_inclusive_variables = $max_inclusive_variables > 0 ? $max_inclusive_variables - 1 : 0;
		
		?>
		
	<div style="float:left; margin-left:20px" class="search_div">
	<div style="clear:both">
		<div style="float:left;">
			<a class="button" onclick="validate_selection()">
			<span><div id="search_div" style="display:inline"><?php echo $the_directory->getSearchButtonCaption() ?></div></span>
			</a>
		</div>
		<div style="float:left; width:50px; position: relative; top: 9px; left: 15px;">
			<div id="loading" style="display:none">
				<?php echo image_tag("loaders/loader.gif")?>
			</div>
		</div>
	</div>	
	</div>		
	</form>	
	<div style="clear:both"></div>
	</div>
	<div id="error_msg" class="error_msg" style="clear:both; display: none; cursor:pointer;" onclick="$(this).hide('slow')">
		<div id="msg_text" ></div>
	</div>
	
<?php end_slot() ?>


<div id="refresh_script">

</div>

      
<?php slot('analytics_script') ?>
	<?php echo html_entity_decode($analytics_script) ?>
<?php end_slot() ?>


<?php slot('sitemap') ?>
<a href="http://<?php echo strtolower($the_directory->getDomain())?>/uploads/sitemap/<?php echo strtolower($the_directory->getDomain())?>/sitemap.xml" target="_blank">Sitemap</a>
<?php end_slot() ?>

<?php slot('fb_app_id'); echo trim($the_directory->getFbApp()); end_slot(); ?>


<script type="text/javascript">

		function validate_selection(){
			var all_selected = true;
	        $("select").each(function()
	        		{
	    				var selected_value = $(this).attr("value");
	    				
	    				if (selected_value == ""){
							var name = $(this).attr("id");
							var name_arr = name.split(".");
							var end_str = name_arr[0];
							var start_str = name_arr[name_arr.length - 1];
							var start_str_arr = start_str.split("_");
							var select_str = "";
							for (var i = 0; i < start_str_arr.length; i++){
								select_str = select_str + " " + start_str_arr[i];
							}
							
							var error_msg = "<?php echo __("Please select")?> " + select_str ;
							$("#error_msg").show();
							$("#msg_text").html(error_msg);
							all_selected = false;
							return false;
		    			}
	        		    // add $(this).val() to your array
	        			//parent_arr.push($(this).parent().attr("id"));
	    				
	        		});
			
	       if (all_selected){
		       $('#loading').show();
		       if ( $.browser.msie ) {
		       		$('#loading').html('<?php echo image_tag("loaders/loader.gif")?>');
		       }
		       $('#search_div').html('<?php echo __("Searching")?>...');
				document.getElementById('search_form').submit();
	       }
		}

       function getChildrendata(childCombo, categoryContentId){
          // alert(categoryContentId); return false;
    	   var str="id=" + categoryContentId + "&name=" + childCombo;
    	   var refresh =  "refresh_script";
		    $.ajax({type: 'POST', url:' <?php echo url_for('template_generation/loadCategoryChildren')?>',  script:true, cache:false, data:  str,

	    	beforeSend: function(){
	            if (categoryContentId == ""){
		              var elem = document.getElementById(childCombo);
		              elem.options.length = 0; 
		              elem.options[0] = new Option('--<?php echo __("Select")?>--', '');
		              return false;
		        }

	       },
				
            success: function(data) {
	            var div_to_refresh = document.getElementById(refresh);
                 $(div_to_refresh).html(data);
               	 
             } });
           
       }

       $(document).ready(function() {
           var elem = document.getElementById("header"); 

           $(elem).css('height', $(elem).height() + <?php echo $max_inclusive_variables ?>  * 30);

           
    	 //  alert($(elem).height());
    	 });
      
       
</script>


<style>
.search_div{
	padding: 5px;
	
}

.search_select{
	font-size: 12px;
    width: 179px;
	
}
.error_msg{
 	background: none repeat scroll 0 0 rgba(255, 0, 0, 0.1);
    border: 1px solid rgba(255, 0, 0, 0.2);
    border-radius: 4px 4px 4px 4px;
    color: rgba(255, 0, 0, 0.7);
    font-weight: bold;
    margin-top: 7px;
    padding: 2px 2px 2px 10px;
	
}

.listing{
	margin-left:20px;
	margin-top:10px;
	line-height:20px;
	
}
</style>